﻿using OSSUtility.Device;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Ozone.Device
{
    /// <summary>
    /// 天平
    /// </summary>
    public class DevBalance : DevBase
    {
        public DevBalance(int CommType, string FSrvIP, int FPort) : base(CommType, FSrvIP, FPort)
        {

        }


        /// <summary>
        /// 获取天平数值
        /// </summary>
        /// <returns></returns>
        public double GetBalanceValue(out string Message)
        {
            double BalanceValue = 0;
            try
            {
                string command = "SI\r\n";
                string recvStr = session_.sendAndReadStr(command, 500);
                Message = recvStr;
                //S D   1002.448 g
                if (!string.IsNullOrEmpty(recvStr))
                {
                    string ss = recvStr.Substring(6, 8);
                    BalanceValue = OSSUtility.Utility.str2double(ss);
                }
                return BalanceValue;
            }
            catch (Exception)
            {
                Message = "ES";
                return 0;
            }


        }


        /// <summary>
        /// 去皮
        /// </summary>
        /// <returns></returns>
        public bool RemoveThePeel()
        {
            try
            {
                string command = "T\r\n";
                string recvStr = session_.sendAndReadStrLock(command, 500);
                if (recvStr == "")
                    return false;
                else
                    return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
